import axios from "axios";

export const request = axios.create({
    baseURL:'/dev-api',
    timeout:5000
})

function loadToken(){
    if(localStorage.getItem('token')){
        return localStorage.getItem('token')
    }else{
        return sessionStorage.getItem('token')
    }
}

// 响应拦截器
request.interceptors.response.use(config=>config.data)

// 请求拦截器
request.interceptors.request.use(req=>{
    const token = loadToken()
    if(token){
        req.headers['Authorization'] = `Bearer ${token}`
    }
    return req
})

// request.get('/api/catche') === '/dev-api/api/catche'